package com.example.shaoying.yuejian.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;


import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.UserGuanZhuAdapter;
import com.example.shaoying.yuejian.javabean.UserGuanzhu;
import com.example.shaoying.yuejian.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class UserGuanZhuActivity extends Activity {

    private RecyclerView recyclerView;
    private UserGuanZhuAdapter userGuanZhuAdapter;
    private String User_Id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.guanzhu);
        recyclerView= (RecyclerView) findViewById(R.id.user_guanzhu_recyclerview);
        User_Id=getIntent().getStringExtra("User_Id");

        UserModel model=new UserModel();
        Call<List<UserGuanzhu>> call=model.getGuanzhu(User_Id);
        call.enqueue(new Callback<List<UserGuanzhu>>() {
            @Override
            public void onResponse(Call<List<UserGuanzhu>> call, Response<List<UserGuanzhu>> response) {
                List<UserGuanzhu> list=response.body();
                userGuanZhuAdapter=new UserGuanZhuAdapter(UserGuanZhuActivity.this,list);
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(UserGuanZhuActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userGuanZhuAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<UserGuanzhu>> call, Throwable t) {
                Toast.makeText(UserGuanZhuActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
